﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace Demo01
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建一个哈希对象
            ArrayList arrayList = new ArrayList();
            Hashtable ht = new Hashtable();
            Student student1 = new Student("001","张澜",19);
            Student student2 = new Student("003", "王五", 18);
            Student student3 = new Student("004", "张三", 17);
            arrayList.Add( student1);
            arrayList.Add( student2);
            arrayList.Add( student3);
            ht.Add(student1.Id,student1);
            ht.Add(student2.Id, student2);
            ht.Add(student3.Id, student3);
            
            while (true) {
            Console.WriteLine("请选择模块：1、添加学生信息。2、删除学生信息 3、查询学生信息");
            int choose = int.Parse(Console.ReadLine());
            if (choose == 1)
                {
                    Console.WriteLine("现在所拥有的学生信息");
                    foreach (var value in ht.Values)
                    {
                        Console.WriteLine(value);
                    }
                Console.WriteLine("请输入要添加的学号：（请勿输入重复的学号！！）");
                string id = Console.ReadLine();
                Console.WriteLine("请输入要添加的学生姓名：");
                string name = Console.ReadLine();
                Console.WriteLine("请输入要添加的学生年龄：");
                    int age = int.Parse(Console.ReadLine());
                //实例化学生对象
                Student student = new Student(id, name, age);
                    if (ht.ContainsKey(id))
                    {
                        Console.WriteLine("您输入的学号已存在");
                        continue;
                    }
                    else
                    {
                        Console.WriteLine("添加成功");
                    }
                    ht.Add(student.Id, student);
                    arrayList.Add(student);
               
                foreach (var value in ht.Values)
                {
                    Console.WriteLine(value);
                }
            }
            else if (choose == 2)
            {
                Console.WriteLine("当前学生信息");
                foreach (var value in ht.Values)
                {
                    Console.WriteLine(value);
                }
                Console.WriteLine("请输入要删除的学生学号：");
                string Id = Console.ReadLine();
                ht.Remove(Id);
                foreach (var value in ht.Values)
                {
                    Console.WriteLine(value);
                }
            }
            else if (choose == 3)
            {
                while (true)
                {
                    Console.WriteLine("请输入选择模块：1、查询所有（按学号排序）2、查询所有（按姓名排序），3、查询所有（按年龄排序）4、按学号查询（查没有，则打印查无此学生）5、退出");
                    int chooes1 = int.Parse(Console.ReadLine());

                        if (chooes1 == 1)
                        {
                            arrayList.Sort(new StudentId());
                            for (int i = 0; i < arrayList.Count; i++)
                            {
                                Console.WriteLine(arrayList[i]);
                            }
                            
                        }
                        else if (chooes1 == 2)
                        {
                            arrayList.Sort(new StudentName());
                            for (int i = 0; i < arrayList.Count; i++)
                            {
                                Console.WriteLine(arrayList[i]);
                            }
                            
                        }
                        else if (chooes1 == 3)
                        {
                            arrayList.Sort(new StudentAge());
                            for (int i = 0; i < arrayList.Count; i++)
                            {
                                Console.WriteLine(arrayList[i]);
                            }
                            
                        }
                    else if (chooes1 == 4)
                    {
                            Console.WriteLine("请输入要查询的学号：00X");
                            string Id1 = Console.ReadLine(); 
                            if (ht.ContainsKey(Id1))
                            {
                                Console.WriteLine(ht[Id1]);
                            }
                            else
                            {
                                Console.WriteLine("查无此人！");
                            }
                    }
                    else if (chooes1 == 5)
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("请输入相应的数字！！");
                    }
                        
                    }
                
            }
            else
            {
                Console.WriteLine("选择错误请重新输入！！");
            }

            

               


            }
        }
















            
        }
    }

